﻿#If RO_SPECIFICS = True Then
'// ========================================================================= '
'// ------------------------------------------------------------------------- '
'//!				\file		CST_Dims.vb
'			        \date		june 2010
'			        \author		TNick
'
'			        \brief		Dialog for 3D points settings
'
'
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'   This file is considered universal knowledge. No restrictions
'   are imposed; use as you see fit.
'   Please read ReadMe.txt and Licence.txt in root folder
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'   
'
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
'//
'//
'//
'//
'//  IMPORTS     ------------------------------------------------------------ '
#Region "Imports"

Imports System.Windows.Forms
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports System.ComponentModel

#End Region
'//  IMPORTS     ============================================================ '
'//
'//
'//
'//
'//  DEFINITIONS    --------------------------------------------------------- '




'//  DEFINITIONS    ========================================================= '
'//
'//
'//
'//
'//  DATA    ---------------------------------------------------------------- '


'//  DATA    ================================================================ '
'//
'//
'//
'//
'//  CLASS    --------------------------------------------------------------- '
Public Class CD_PAD

    Private AdvPrp As CADVPRP
    Private m_SortParc As ColumnHeader
    Private m_SortConst As ColumnHeader

    '// --------------------------------------------------------------------- '
    Public Sub LoadPadData(ByRef PadD As PADDATA)
        Dim li As System.Windows.Forms.ListViewItem

        '// will not go far if we don't have this
        Dim acDoc As Document = _
        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        If (acDoc Is Nothing) Then
            Me.Close()
            Return
        End If

        '// enshure a name for layers
        If (String.IsNullOrEmpty(PadD.ppr.Ly_Tbl)) Then
            PadD.ppr.Ly_Tbl = "0"
        End If
        If (String.IsNullOrEmpty(PadD.ppr.Ly_Var)) Then
            PadD.ppr.Ly_Var = "0"
        End If
        If (String.IsNullOrEmpty(PadD.ppr.Ly_Vp)) Then
            PadD.ppr.Ly_Vp = "0"
        End If

        '// copy simple definitions
        Me.CB_F_Format.Text = PadD.ppr.Format
        Me.CK_F_Overwr.Checked = PadD.ppr.Overwr
        Me.RB_F_Po.Checked = PadD.ppr.Po
        Me.RB_F_Ln.Checked = Not PadD.ppr.Po
        If (String.IsNullOrEmpty(PadD.ppr.Name)) Then
            Me.TX_F_Name.Text = "PAD"
        Else
            Me.TX_F_Name.Text = PadD.ppr.Name
        End If
        If (PadD.ppr.TextH < 0.01) Or (PadD.ppr.TextH > 100) Then
            PadD.ppr.TextH = 2.5
        End If
        Me.UD_F_TextH.Value = PadD.ppr.TextH
        Me.CB_Ly_Tbl.Text = PadD.ppr.Ly_Tbl
        Me.CB_Ly_Var.Text = PadD.ppr.Ly_Var
        Me.CB_Ly_Vp.Text = PadD.ppr.Ly_Vp

        '// get parcels in list
        Me.LV_Parcels.Items.Clear()
        If (PadD.Parcels IsNot Nothing) Then
            For Each pc As PADPARC In PadD.Parcels
                li = Me.LV_Parcels.Items.Add(pc.Name)
                li.SubItems.Add(pc.Categ)
                li.SubItems.Add(pc.Supr.ToString)
                li.SubItems.Add(pc.ValImp)
                li.SubItems.Add(pc.Tip)
            Next
        End If
        Me.LV_Parcels.Tag = Nothing

        '// get buildings in list
        Me.LV_Constr.Items.Clear()
        If (PadD.Constr IsNot Nothing) Then
            For Each pc As PADCONST In PadD.Constr
                li = Me.LV_Constr.Items.Add(pc.Code)
                li.SubItems.Add(pc.Categ)
                li.SubItems.Add(pc.Supr.ToString)
                li.SubItems.Add(pc.ValImp)
                li.SubItems.Add(pc.Tip)
            Next
        End If
        Me.LV_Constr.Tag = Nothing

        '// get points in list
        Me.TX_Coord.Text = ""
        If (PadD.Coord IsNot Nothing) Then
            For Each pc As PADCRD In PadD.Coord
                Me.TX_Coord.Text = Me.TX_Coord.Text & _
                    pc.PtName & vbTab & _
                    pc.dN.ToString & vbTab & _
                    pc.dE.ToString & vbNewLine
            Next
        End If

        '// other simple properties
        Me.TX_Address.Text = PadD.Address
        Me.TX_CF.Text = PadD.CF
        Me.TX_NrCad.Text = PadD.NrCad
        Me.TX_SuprAct.Text = PadD.SuprAct
        Me.TX_SuprMas.Text = PadD.SuprMas
        Me.TX_UAT.Text = PadD.UAT
        If (String.IsNullOrEmpty(PadD.CoordF_XY)) Then
            PadD.CoordF_XY = "0.000"
        End If
        If (String.IsNullOrEmpty(PadD.CoordF_Z)) Then
            PadD.CoordF_Z = "0.000"
        End If
        Me.TX_C_XY.Text = PadD.CoordF_XY
        Me.TX_C_Z.Text = PadD.CoordF_Z

        '// advanced properties
        AdvPrp = New CADVPRP(PadD)
        PRP_Adv.SelectedObject = AdvPrp


        '// time for hard work: available printers and layers
        Using acLock As DocumentLock = acDoc.LockDocument
            Using acTrans As Transaction = _
                acDoc.Database.TransactionManager.StartTransaction()
                Try
                    '// returns the layer table for the current database
                    Dim acLyrTbl As LayerTable = _
                    DirectCast(acTrans.GetObject(acDoc.Database.LayerTableId, OpenMode.ForRead),  _
                        LayerTable)

                    '' Step through the Layer table and get each layer name
                    For Each acObjId As ObjectId In acLyrTbl
                        Dim acLyrTblRec As LayerTableRecord
                        acLyrTblRec = _
                            DirectCast(acTrans.GetObject(acObjId, OpenMode.ForRead),  _
                            LayerTableRecord)

                        Me.CB_Ly_Tbl.Items.Add(acLyrTblRec.Name)
                        Me.CB_Ly_Var.Items.Add(acLyrTblRec.Name)
                        Me.CB_Ly_Vp.Items.Add(acLyrTblRec.Name)

                    Next

                    '// get the printers in combo
                    Dim psv As PlotSettingsValidator
                    Dim iIdx As Integer
                    Dim bInit As Boolean = False
                    If (String.IsNullOrEmpty(PadD.ppr.Printer)) Then
                        PadD.ppr.Printer = "None"
                    End If
                    If (String.IsNullOrEmpty(PadD.ppr.Format)) Then
                        PadD.ppr.Format = "A4"
                    End If

                    psv = PlotSettingsValidator.Current
                    Dim sc As System.Collections.Specialized.StringCollection = _
                        psv.GetPlotDeviceList()
                    For Each sPrint As String In sc
                        iIdx = Me.CB_F_Printer.Items.Add(sPrint)
                        If (sPrint.ToUpper = PadD.ppr.Printer.ToUpper) Then
                            Me.CB_F_Printer.SelectedIndex = iIdx
                            bInit = True
                        End If
                    Next
                    If bInit = False Then
                        Me.CB_F_Printer.SelectedIndex = 0
                    End If

                    For i As Integer = 0 To Me.CB_F_Format.Items.Count - 1
                        If (Me.CB_F_Format.Items(i).ToString = PadD.ppr.Format) Then
                            Me.CB_F_Format.SelectedIndex = i
                            Exit For
                        End If
                    Next

                    acTrans.Commit()
                Catch ex As Exception
                    acTrans.Abort()
                    CMain.DebugException(ex)
                    Me.Close()
                End Try
            End Using '' Dispose of the transaction
        End Using
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Public Function SavePadData(ByRef PadD As PADDATA) As Boolean

        Try

            '// copy simple properties and check while at it
            PadD.ppr.Printer = Me.CB_F_Printer.Text
            PadD.ppr.Format = Me.CB_F_Format.Text
            PadD.ppr.Overwr = Me.CK_F_Overwr.Checked
            PadD.ppr.Po = Me.RB_F_Po.Checked
            PadD.ppr.Name = Me.TX_F_Name.Text
            If (String.IsNullOrEmpty(Me.TX_F_Name.Text)) Then
                Autodesk.AutoCAD.ApplicationServices.Application. _
                    ShowAlertDialog("Numele foii nu a fost precizat")
                Me.TABC_Main.SelectedTab = TP_Various
                Return False
            End If
            PadD.ppr.TextH = Me.UD_F_TextH.Value

            '// enshure a layer
            PadD.ppr.Ly_Tbl = Me.CB_Ly_Tbl.Text
            PadD.ppr.Ly_Var = Me.CB_Ly_Var.Text
            PadD.ppr.Ly_Vp = Me.CB_Ly_Vp.Text
            If (String.IsNullOrEmpty(PadD.ppr.Ly_Tbl)) Then
                PadD.ppr.Ly_Tbl = "0"
            End If
            If (String.IsNullOrEmpty(PadD.ppr.Ly_Var)) Then
                PadD.ppr.Ly_Var = "0"
            End If
            If (String.IsNullOrEmpty(PadD.ppr.Ly_Vp)) Then
                PadD.ppr.Ly_Vp = "0"
            End If

            '// get parcels in array
            If (Me.LV_Parcels.Items.Count = 0) Then
                PadD.Parcels = Nothing
            Else
                ReDim PadD.Parcels(0 To Me.LV_Parcels.Items.Count - 1)
                For i As Integer = 0 To Me.LV_Parcels.Items.Count - 1
                    With Me.LV_Parcels.Items(i)
                        Try
                            PadD.Parcels(i).Name = .SubItems(0).Text
                            PadD.Parcels(i).Categ = .SubItems(1).Text
                            CMain.GetDbl(.SubItems(2).Text, PadD.Parcels(i).Supr)
                            PadD.Parcels(i).ValImp = .SubItems(3).Text
                            PadD.Parcels(i).Tip = .SubItems(4).Text
                        Catch ex As System.Exception
                            Me.TABC_Main.SelectedTab = TP_Parcels
                            Me.LV_Constr.Items(i).Selected = True
                            Autodesk.AutoCAD.ApplicationServices.Application. _
                                ShowAlertDialog("Datele pentru parcela " & _
                                                Me.LV_Parcels.Items(i).Text & _
                                                " nu au putut fi interpretate")
                            Return False
                        End Try
                    End With
                Next
            End If

            '// get buildings in array
            If (Me.LV_Constr.Items.Count = 0) Then
                PadD.Constr = Nothing
            Else
                ReDim PadD.Constr(0 To Me.LV_Constr.Items.Count - 1)
                For i As Integer = 0 To Me.LV_Constr.Items.Count - 1
                    Try
                        With Me.LV_Constr.Items(i)
                            PadD.Constr(i).Code = .SubItems(0).Text
                            PadD.Constr(i).Categ = .SubItems(1).Text
                            PadD.Constr(i).Supr = CDbl(.SubItems(2).Text)
                            PadD.Constr(i).ValImp = .SubItems(3).Text
                            PadD.Constr(i).Tip = .SubItems(4).Text
                        End With
                    Catch ex As System.Exception
                        Me.TABC_Main.SelectedTab = TP_Constr
                        Me.LV_Constr.Items(i).Selected = True
                        Autodesk.AutoCAD.ApplicationServices.Application. _
                            ShowAlertDialog("Datele pentru constructia " & _
                                            Me.LV_Constr.Items(i).Text & _
                                            " nu au putut fi interpretate")
                        Return False
                    End Try
                Next
            End If

            '// get points in array
            If (String.IsNullOrEmpty(Me.TX_Coord.Text)) Then
                PadD.Coord = Nothing
            Else
                PadD.Coord = Nothing
                Dim chSplit(1) As Char
                chSplit(0) = vbCr
                chSplit(1) = vbLf
                Dim lnAry() As String
                Dim elAry() As String
                lnAry = Me.TX_Coord.Text.Split(chSplit, _
                     StringSplitOptions.RemoveEmptyEntries)
                If (lnAry IsNot Nothing) Then
                    chSplit(0) = " "c
                    chSplit(1) = vbTab
                    For Each sLine As String In lnAry
                        elAry = sLine.Split(chSplit, _
                            StringSplitOptions.RemoveEmptyEntries)
                        If (elAry IsNot Nothing) Then
                            If elAry.Length < 3 Then
Coord_Ln_Err:
                                Me.TABC_Main.SelectedTab = TP_Coord
                                Autodesk.AutoCAD.ApplicationServices.Application. _
                                    ShowAlertDialog("Coordonate: Linia urmatoare:" & _
                                                    vbNewLine & sLine & vbNewLine & _
                                                    "nu a putut fi interpretata" & vbNewLine & _
                                                    "Formatul asteptat este <Nume Nord Est>" & vbNewLine & _
                                                    "Spatiul si TAB-ul sunt separatori." & vbNewLine & _
                                                    "Elementele urmatoare (precum Z, cod) sunt ignorate")
                                Return False
                            End If
                            Dim pcr As PADCRD
                            pcr.PtName = elAry(0)
                            If (CMain.GetDbl(elAry(1), pcr.dN) = False) Then GoTo Coord_Ln_Err
                            If (CMain.GetDbl(elAry(2), pcr.dE) = False) Then GoTo Coord_Ln_Err

                            If (PadD.Coord Is Nothing) Then
                                ReDim PadD.Coord(0 To 0)
                            Else
                                ReDim Preserve PadD.Coord(0 To PadD.Coord.Length)
                            End If
                            PadD.Coord(PadD.Coord.Length - 1) = pcr
                        End If
                    Next
                End If
            End If

            '// some easy options at the end
            PadD.Address = Me.TX_Address.Text
            PadD.CF = Me.TX_CF.Text
            PadD.NrCad = Me.TX_NrCad.Text
            PadD.SuprAct = Me.TX_SuprAct.Text
            PadD.SuprMas = Me.TX_SuprMas.Text
            PadD.UAT = Me.TX_UAT.Text
            PadD.CoordF_XY = Me.TX_C_XY.Text
            PadD.CoordF_Z = Me.TX_C_Z.Text
            If (String.IsNullOrEmpty(PadD.CoordF_XY)) Then
                PadD.CoordF_XY = "0.000"
            End If
            If (String.IsNullOrEmpty(PadD.CoordF_Z)) Then
                PadD.CoordF_Z = "0.000"
            End If
            AdvPrp.GetValues(PadD)

        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub Enable_Parc(ByVal bEn As Boolean)
        Me.TX_P_Name.Enabled = bEn
        Me.TX_P_Categ.Enabled = bEn
        Me.TX_P_Supr.Enabled = bEn
        Me.TX_P_ValImp.Enabled = bEn
        Me.TX_P_Tip.Enabled = bEn
        If (bEn = False) Then
            Me.TX_P_Name.Text = ""
            Me.TX_P_Categ.Text = ""
            Me.TX_P_Supr.Text = ""
            Me.TX_P_ValImp.Text = ""
            Me.TX_P_Tip.Text = ""
            Me.LV_Parcels.Tag = Nothing
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub Enable_Const(ByVal bEn As Boolean)
        Me.TX_C_Code.Enabled = bEn
        Me.TX_C_Categ.Enabled = bEn
        Me.TX_C_Supr.Enabled = bEn
        Me.TX_C_ValImp.Enabled = bEn
        Me.TX_C_Tip.Enabled = bEn
        If (bEn = False) Then
            Me.TX_C_Code.Text = ""
            Me.TX_C_Categ.Text = ""
            Me.TX_C_Supr.Text = ""
            Me.TX_C_ValImp.Text = ""
            Me.TX_C_Tip.Text = ""
            Me.LV_Constr.Tag = Nothing
        End If
    End Sub
    '// ===================================================================== '




    '// --------------------------------------------------------------------- '
    Private Sub OK_Button_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles OK_Button.Click

        Dim locPad As PADDATA = Nothing
        Dim bOK As Boolean = False


        Dim acDoc As Document = _
        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        If (acDoc Is Nothing) Then
            Me.Close()
            Return
        End If

        Me.Hide()
        If (SavePadData(locPad)) Then
            Using acLock As DocumentLock = acDoc.LockDocument
                If (CM_RO_Tables.Create_PAD(acDoc, locPad) = True) Then
                    bOK = True
                    CM_RO_Tables.Stgs.PadStg = locPad
                    Me.DialogResult = System.Windows.Forms.DialogResult.OK
                    Me.Close()
                End If
            End Using
        End If
        If (bOK = False) Then
            Me.Show()
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub Cancel_Button_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles Cancel_Button.Click


        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub CD_PAD_Load( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles MyBase.Load

        Enable_Parc(False)
        Enable_Const(False)

        LoadPadData(CM_RO_Tables.Stgs.PadStg)

    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub LV_Constr_SelectedIndexChanged( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles LV_Constr.SelectedIndexChanged

        If (Me.LV_Constr.Tag IsNot Nothing) Then
            With LV_Constr.Items(CInt(Me.LV_Constr.Tag))
                .SubItems(0).Text = Me.TX_C_Code.Text
                .SubItems(1).Text = Me.TX_C_Categ.Text
                .SubItems(2).Text = Me.TX_C_Supr.Text
                .SubItems(3).Text = Me.TX_C_ValImp.Text
                .SubItems(4).Text = Me.TX_C_Tip.Text
            End With
        End If

        If (LV_Constr.SelectedItems.Count = 1) Then
            With LV_Constr.SelectedItems(0)
                Me.TX_C_Code.Text = .SubItems(0).Text
                Me.TX_C_Categ.Text = .SubItems(1).Text
                Me.TX_C_Supr.Text = .SubItems(2).Text
                Me.TX_C_ValImp.Text = .SubItems(3).Text
                Me.TX_C_Tip.Text = .SubItems(4).Text
                Me.LV_Constr.Tag = .Index
            End With
            Enable_Const(True)
        Else
            Enable_Const(False)
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub LV_Parcels_SelectedIndexChanged( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles LV_Parcels.SelectedIndexChanged

        If (Me.LV_Parcels.Tag IsNot Nothing) Then
            With LV_Parcels.Items(CInt(Me.LV_Parcels.Tag))
                .SubItems(0).Text = Me.TX_P_Name.Text
                .SubItems(1).Text = Me.TX_P_Categ.Text
                .SubItems(2).Text = Me.TX_P_Supr.Text
                .SubItems(3).Text = Me.TX_P_ValImp.Text
                .SubItems(4).Text = Me.TX_P_Tip.Text
            End With
        End If

        If (Me.LV_Parcels.SelectedItems.Count = 1) Then
            With LV_Parcels.SelectedItems(0)
                Me.TX_P_Name.Text = .SubItems(0).Text
                Me.TX_P_Categ.Text = .SubItems(1).Text
                Me.TX_P_Supr.Text = .SubItems(2).Text
                Me.TX_P_ValImp.Text = .SubItems(3).Text
                Me.TX_P_Tip.Text = .SubItems(4).Text
                Me.LV_Parcels.Tag = .Index
            End With
            Enable_Parc(True)
        Else
            Enable_Parc(False)
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub CB_F_Printer_SelectedIndexChanged( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles CB_F_Printer.SelectedIndexChanged

        Dim ps As PlotSettings = Nothing
        Try
            Me.CB_F_Format.Items.Clear()
            Dim psv As PlotSettingsValidator
            psv = PlotSettingsValidator.Current
            ps = New PlotSettings(True)

            psv.SetPlotConfigurationName(ps, Me.CB_F_Printer.Text, Nothing)
            psv.RefreshLists(ps)

            Dim sc As System.Collections.Specialized.StringCollection = _
                psv.GetCanonicalMediaNameList(ps)
            For Each sPrint As String In sc
                Me.CB_F_Format.Items.Add(sPrint)
            Next
            Me.CB_F_Format.SelectedIndex = 0
            ps.Dispose()
        Catch ex As System.Exception
            Debug.Print("Exception in getting paper format")
        Finally
            If (ps IsNot Nothing) Then
                ps.Dispose()
                ps = Nothing
            End If
        End Try
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub B_C_Add_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles B_C_Add.Click

        Dim li As System.Windows.Forms.ListViewItem

        li = Me.LV_Constr.Items.Add("C?")
        li.SubItems.Add("")
        li.SubItems.Add(0)
        li.SubItems.Add(0)
        li.SubItems.Add("")

    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub B_P_Add_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles B_P_Add.Click

        Dim li As System.Windows.Forms.ListViewItem
        li = Me.LV_Parcels.Items.Add("Lot ?")
        li.SubItems.Add("")
        li.SubItems.Add(0)
        li.SubItems.Add(0)
        li.SubItems.Add("")

    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub B_C_Rem_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles B_C_Rem.Click

        If (Me.LV_Constr.SelectedItems.Count = 1) Then
            Me.LV_Constr.SelectedItems(0).Remove()
            Me.LV_Constr.Tag = Nothing
            Enable_Const(False)
        Else
            Autodesk.AutoCAD.ApplicationServices.Application. _
                ShowAlertDialog(CMain._T(TX.NOSELLI))
        End If

    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub B_P_Rem_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles B_P_Rem.Click

        If (LV_Parcels.SelectedItems.Count = 1) Then
            LV_Parcels.SelectedItems(0).Remove()
            Me.LV_Parcels.Tag = Nothing
            Enable_Parc(False)
        Else
            Autodesk.AutoCAD.ApplicationServices.Application. _
                ShowAlertDialog(CMain._T(TX.NOSELLI))
        End If

    End Sub
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    Private Sub TX_P_Name_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_P_Name.Validated

        If (Me.LV_Parcels.Tag IsNot Nothing) Then
            With LV_Parcels.Items(CInt(Me.LV_Parcels.Tag))
                .SubItems(0).Text = Me.TX_P_Name.Text
            End With
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub TX_P_Categ_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_P_Categ.Validated

        If (Me.LV_Parcels.Tag IsNot Nothing) Then
            With LV_Parcels.Items(CInt(Me.LV_Parcels.Tag))
                .SubItems(1).Text = Me.TX_P_Categ.Text
            End With
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub TX_P_Supr_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_P_Supr.Validated

        If (Me.LV_Parcels.Tag IsNot Nothing) Then
            With LV_Parcels.Items(CInt(Me.LV_Parcels.Tag))
                .SubItems(2).Text = Me.TX_P_Supr.Text
            End With
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub TX_P_ValImp_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_P_ValImp.Validated

        If (Me.LV_Parcels.Tag IsNot Nothing) Then
            With LV_Parcels.Items(CInt(Me.LV_Parcels.Tag))
                .SubItems(3).Text = Me.TX_P_ValImp.Text
            End With
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub TX_P_Tip_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_P_Tip.Validated

        If (Me.LV_Parcels.Tag IsNot Nothing) Then
            With LV_Parcels.Items(CInt(Me.LV_Parcels.Tag))
                .SubItems(4).Text = Me.TX_P_Tip.Text
            End With
        End If
    End Sub
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    Private Sub TX_C_Code_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_C_Code.Validated

        If (Me.LV_Constr.Tag IsNot Nothing) Then
            With LV_Constr.Items(CInt(Me.LV_Constr.Tag))
                .SubItems(0).Text = Me.TX_C_Code.Text
            End With
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub TX_C_Categ_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_C_Categ.Validated

        If (Me.LV_Constr.Tag IsNot Nothing) Then
            With LV_Constr.Items(CInt(Me.LV_Constr.Tag))
                .SubItems(1).Text = Me.TX_C_Categ.Text
            End With
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub TX_C_Supr_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_C_Supr.Validated

        If (Me.LV_Constr.Tag IsNot Nothing) Then
            With LV_Constr.Items(CInt(Me.LV_Constr.Tag))
                .SubItems(2).Text = Me.TX_C_Supr.Text
            End With
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub TX_C_ValImp_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_C_ValImp.Validated

        If (Me.LV_Constr.Tag IsNot Nothing) Then
            With LV_Constr.Items(CInt(Me.LV_Constr.Tag))
                .SubItems(3).Text = Me.TX_C_ValImp.Text
            End With
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub TX_C_Tip_Validated( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles TX_C_Tip.Validated

        If (Me.LV_Constr.Tag IsNot Nothing) Then
            With LV_Constr.Items(CInt(Me.LV_Constr.Tag))
                .SubItems(4).Text = Me.TX_C_Tip.Text
            End With
        End If
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub RB_Advanced_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles RB_Advanced.Click

        If (RB_Advanced.Checked = False) Then
            PRP_Adv.Visible = True
            TABC_Main.Visible = False
            RB_Advanced.Checked = True
        Else
            PRP_Adv.Visible = False
            TABC_Main.Visible = True
            RB_Advanced.Checked = False
        End If

    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub B_Open_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles B_Open.Click

        Try

            Dim fdlg As OpenFileDialog = New OpenFileDialog()

            fdlg.Title = "Alegeti fisierul"
            fdlg.Filter = CMain._T(TX.XMLFILES) & " (*.xml)|*.xml|" & _
                          CMain._T(TX.ALLFILES) & " (*.*)|*.*"
            fdlg.FilterIndex = 0
            fdlg.RestoreDirectory = False
            fdlg.CheckFileExists = True
            fdlg.FileName = CM_RO_Tables.Stgs.PadStg.src_file
            If fdlg.ShowDialog() = DialogResult.OK Then
                Dim loc_padd As PADDATA = Nothing
                CM_RO_Tables.Load_Pad_From_File( _
                    loc_padd, _
                    fdlg.FileName)
                LoadPadData(loc_padd)
                CM_RO_Tables.Stgs.PadStg.src_file = fdlg.FileName
            End If

        Catch ex As System.Exception
            CMain.DebugException(ex)
            CMain.PopUpExc()
        End Try

    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub B_Save_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles B_Save.Click

        Try

            Dim fdlg As SaveFileDialog = New SaveFileDialog()

            fdlg.Title = "Selectati locatia pentru salvare"
            fdlg.Filter = CMain._T(TX.XMLFILES) & " (*.xml)|*.xml|" & _
                          CMain._T(TX.ALLFILES) & " (*.*)|*.*"
            fdlg.FilterIndex = 0
            fdlg.RestoreDirectory = False
            fdlg.CheckPathExists = True
            fdlg.OverwritePrompt = True
            fdlg.FileName = CM_RO_Tables.Stgs.PadStg.src_file
            If fdlg.ShowDialog() = DialogResult.OK Then
                Dim lc_Pad_d As PADDATA = Nothing
                If SavePadData(lc_Pad_d) Then
                    CM_RO_Tables.Save_Pad_To_File( _
                        lc_Pad_d, _
                        fdlg.FileName)
                    CM_RO_Tables.Stgs.PadStg.src_file = fdlg.FileName
                End If
            End If
        Catch ex As System.Exception
            CMain.DebugException(ex)
            CMain.PopUpExc()
        End Try

    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub LV_Parcels_ColumnClick( _
        ByVal sender As System.Object, _
        ByVal e As System.Windows.Forms.ColumnClickEventArgs) _
        Handles LV_Parcels.ColumnClick

        '// code copied from
        '// http://www.vb-helper.com/howto_net_listview_sort_clicked_column.html

        ' Get the new sorting column.
        Dim new_sorting_column As ColumnHeader = _
            Me.LV_Parcels.Columns(e.Column)

        ' Figure out the new sorting order.
        Dim sort_order As System.Windows.Forms.SortOrder
        If m_SortParc Is Nothing Then
            ' New column. Sort ascending.
            sort_order = SortOrder.Ascending
        Else
            ' See if this is the same column.
            If new_sorting_column.Equals(m_SortParc) Then
                ' Same column. Switch the sort order.
                If m_SortParc.Text.StartsWith("^") Then
                    sort_order = SortOrder.Descending
                Else
                    sort_order = SortOrder.Ascending
                End If
            Else
                ' New column. Sort ascending.
                sort_order = SortOrder.Ascending
            End If

            ' Remove the old sort indicator.
            m_SortParc.Text = _
                m_SortParc.Text.Substring(2)
        End If

        ' Display the new sort order.
        m_SortParc = new_sorting_column
        If sort_order = SortOrder.Ascending Then
            m_SortParc.Text = "^ " & m_SortParc.Text
        Else
            m_SortParc.Text = "v " & m_SortParc.Text
        End If

        ' Create a comparer.
        Me.LV_Parcels.ListViewItemSorter = New  _
            ListViewComparer(e.Column, sort_order)

        ' Sort.
        Me.LV_Parcels.Sort()


    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub LV_Constr_ColumnClick( _
        ByVal sender As System.Object, _
        ByVal e As System.Windows.Forms.ColumnClickEventArgs) _
        Handles LV_Constr.ColumnClick

        '// code copied from
        '// http://www.vb-helper.com/howto_net_listview_sort_clicked_column.html

        ' Get the new sorting column.
        Dim new_sorting_column As ColumnHeader = _
            Me.LV_Constr.Columns(e.Column)

        ' Figure out the new sorting order.
        Dim sort_order As System.Windows.Forms.SortOrder
        If m_SortConst Is Nothing Then
            ' New column. Sort ascending.
            sort_order = SortOrder.Ascending
        Else
            ' See if this is the same column.
            If new_sorting_column.Equals(m_SortConst) Then
                ' Same column. Switch the sort order.
                If m_SortConst.Text.StartsWith("^") Then
                    sort_order = SortOrder.Descending
                Else
                    sort_order = SortOrder.Ascending
                End If
            Else
                ' New column. Sort ascending.
                sort_order = SortOrder.Ascending
            End If

            ' Remove the old sort indicator.
            m_SortConst.Text = _
                m_SortConst.Text.Substring(2)
        End If

        ' Display the new sort order.
        m_SortConst = new_sorting_column
        If sort_order = SortOrder.Ascending Then
            m_SortConst.Text = "^ " & m_SortConst.Text
        Else
            m_SortConst.Text = "v " & m_SortConst.Text
        End If

        ' Create a comparer.
        Me.LV_Constr.ListViewItemSorter = New  _
            ListViewComparer(e.Column, sort_order)

        ' Sort.
        Me.LV_Constr.Sort()

    End Sub
    '// ===================================================================== '






    '// --------------------------------------------------------------------- '
    Private Class CADVPRP
        '// internal data
        Private int_d As PADADV

        '// Constructor
        Public Sub New(ByRef sIn As PADDATA)
            int_d = sIn.adv
        End Sub

        '// return altered data
        Public Sub GetValues(ByRef sIn As PADDATA)
            sIn.adv = int_d
        End Sub

        <CategoryAttribute("Atribute"), _
        DescriptionAttribute("Numele celui care executa lucrarea"), _
        DefaultValueAttribute("?")> _
        Public Property Text_Executat() As String
            Get
                Return int_d.sExecname
            End Get
            Set(ByVal Value As String)
                int_d.sExecname = Value
            End Set
        End Property

        <CategoryAttribute("Atribute"), _
        DescriptionAttribute("Data realizarii planului; lasati campul gol pentru auto-generare"), _
        DefaultValueAttribute("")> _
        Public Property Text_Data() As String
            Get
                Return int_d.sData
            End Get
            Set(ByVal Value As String)
                int_d.sData = Value
            End Set
        End Property

        <CategoryAttribute("Texte"), _
        DescriptionAttribute("Dimensiunea anexei raportata la dimensiunea textului"), _
        DefaultValueAttribute(0.8)> _
        Public Property Marime_Text_Anexa() As Double
            Get
                Return int_d.dTxR_Anexa
            End Get
            Set(ByVal Value As Double)
                int_d.dTxR_Anexa = Value
            End Set
        End Property

        <CategoryAttribute("Texte"), _
        DescriptionAttribute("Dimensiunea titlului raportata la dimensiunea textului"), _
        DefaultValueAttribute(1.2)> _
        Public Property Marime_Text_Titlu() As Double
            Get
                Return int_d.dTxR_Title
            End Get
            Set(ByVal Value As Double)
                int_d.dTxR_Title = Value
            End Set
        End Property

        <CategoryAttribute("Texte"), _
        DescriptionAttribute("Dimensiunea scarii raportata la dimensiunea textului"), _
        DefaultValueAttribute(1)> _
        Public Property Marime_Text_Scara() As Double
            Get
                Return int_d.dTxR_Scale
            End Get
            Set(ByVal Value As Double)
                int_d.dTxR_Scale = Value
            End Set
        End Property

        <CategoryAttribute("Alinieri"), _
        DescriptionAttribute("Procentul din inaltiumea textului folosit ca si spatiu liber"), _
        DefaultValueAttribute(0.1)> _
        Public Property Spatiu_Inainte_De_Text() As Double
            Get
                Return int_d.dTxR_Al
            End Get
            Set(ByVal Value As Double)
                int_d.dTxR_Al = Value
            End Set
        End Property
        <CategoryAttribute("Alinieri"), _
        DescriptionAttribute("Procentul din inaltiumea textului folosit ca si spatiu liber pentru tabele (verical)"), _
        DefaultValueAttribute(0.1)> _
        Public Property Spatiu_Lateral_Tabel() As Double
            Get
                Return int_d.dB_Al_H
            End Get
            Set(ByVal Value As Double)
                int_d.dB_Al_H = Value
            End Set
        End Property
        <CategoryAttribute("Alinieri"), _
        DescriptionAttribute("Procentul din inaltiumea textului folosit ca si spatiu liber pentru tabele (orizointal)"), _
        DefaultValueAttribute(0.1)> _
        Public Property Spatiu_Vertical_Tabel() As Double
            Get
                Return int_d.dB_Al_V
            End Get
            Set(ByVal Value As Double)
                int_d.dB_Al_V = Value
            End Set
        End Property


        <CategoryAttribute("Randuri"), _
        DescriptionAttribute("Inaltimea unui rand raportata la inaltimea textului"), _
        DefaultValueAttribute(0.1)> _
        Public Property Inaltimea_Randului_In_Tabel() As Double
            Get
                Return int_d.dRoR_1
            End Get
            Set(ByVal Value As Double)
                int_d.dRoR_1 = Value
            End Set
        End Property

        <CategoryAttribute("Randuri"), _
        DescriptionAttribute("Inaltimea unui rand dublu raportata la inaltimea textului"), _
        DefaultValueAttribute(0.1)> _
        Public Property Inaltimea_Randului_Dublu_In_Tabel() As Double
            Get
                Return int_d.dRoR_2
            End Get
            Set(ByVal Value As Double)
                int_d.dRoR_2 = Value
            End Set
        End Property

        <CategoryAttribute("Tabel - antet"), _
        DescriptionAttribute("Latimea primei coloane (Nr. cad., CF)"), _
        DefaultValueAttribute(10)> _
        Public Property Tabel_Antet_Coloana_1() As Double
            Get
                Return int_d.dClR_Top_1
            End Get
            Set(ByVal Value As Double)
                int_d.dClR_Top_1 = Value
            End Set
        End Property

        <CategoryAttribute("Tabel - antet"), _
        DescriptionAttribute("Latimea coloanei 2 (Suprafata)"), _
        DefaultValueAttribute(10)> _
        Public Property Tabel_Antet_Coloana_2() As Double
            Get
                Return int_d.dCLR_Top_2
            End Get
            Set(ByVal Value As Double)
                int_d.dCLR_Top_2 = Value
            End Set
        End Property

        <CategoryAttribute("Tabel - antet"), _
        DescriptionAttribute("Latimea coloanei 3 (UAT)"), _
        DefaultValueAttribute(4)> _
        Public Property Tabel_Antet_Coloana_3() As Double
            Get
                Return int_d.dClR_Top_3
            End Get
            Set(ByVal Value As Double)
                int_d.dClR_Top_3 = Value
            End Set
        End Property


        <CategoryAttribute("Tabel parcele-constructii"), _
        DescriptionAttribute("Latimea primei coloane (Nume)"), _
        DefaultValueAttribute(10)> _
        Public Property Tabel_Parcele_Constructii_Coloana_1() As Double
            Get
                Return int_d.dClR_Mid_1
            End Get
            Set(ByVal Value As Double)
                int_d.dClR_Mid_1 = Value
            End Set
        End Property

        <CategoryAttribute("Tabel parcele-constructii"), _
        DescriptionAttribute("Latimea coloanei 2 (Categoria de folosinta)"), _
        DefaultValueAttribute(10)> _
        Public Property Tabel_Parcele_Constructii_Coloana_2() As Double
            Get
                Return int_d.dCLR_Mid_2
            End Get
            Set(ByVal Value As Double)
                int_d.dCLR_Mid_2 = Value
            End Set
        End Property

        <CategoryAttribute("Tabel parcele-constructii"), _
        DescriptionAttribute("Latimea coloanei 3 (Suprafata)"), _
        DefaultValueAttribute(10)> _
        Public Property Tabel_Parcele_Constructii_Coloana_3() As Double
            Get
                Return int_d.dClR_Mid_3
            End Get
            Set(ByVal Value As Double)
                int_d.dClR_Mid_3 = Value
            End Set
        End Property

        <CategoryAttribute("Tabel parcele-constructii"), _
        DescriptionAttribute("Latimea coloanei 4 (Valoarea de impozitare)"), _
        DefaultValueAttribute(10)> _
        Public Property Tabel_Parcele_Constructii_Coloana_4() As Double
            Get
                Return int_d.dClR_Mid_4
            End Get
            Set(ByVal Value As Double)
                int_d.dClR_Mid_4 = Value
            End Set
        End Property


        <CategoryAttribute("Tabel coordonate"), _
        DescriptionAttribute("Latimea coloanei pentru numarul punctului"), _
        DefaultValueAttribute(8)> _
        Public Property Tabel_Coordonate_Coloana_Numar() As Double
            Get
                Return int_d.dClR_Btm_Idx
            End Get
            Set(ByVal Value As Double)
                int_d.dClR_Btm_Idx = Value
            End Set
        End Property
        <CategoryAttribute("Tabel coordonate"), _
        DescriptionAttribute("Latimea coloanei pentru coordonate"), _
        DefaultValueAttribute(8)> _
        Public Property Tabel_Coordonate_Coloane_Coordonate() As Double
            Get
                Return int_d.dCLR_Btm_Coord
            End Get
            Set(ByVal Value As Double)
                int_d.dCLR_Btm_Coord = Value
            End Set
        End Property
        <CategoryAttribute("Tabel coordonate"), _
        DescriptionAttribute("Latimea coloanei pentru separator"), _
        DefaultValueAttribute(8)> _
        Public Property Tabel_Coordonate_Coloana_Separator() As Double
            Get
                Return int_d.dCLR_Btm_Coord
            End Get
            Set(ByVal Value As Double)
                int_d.dCLR_Btm_Coord = Value
            End Set
        End Property
        <CategoryAttribute("Tabel coordonate"), _
        DescriptionAttribute("Inaltime minima tabel raportata la inaltimea textului"), _
        DefaultValueAttribute(8)> _
        Public Property Tabel_Coordonate_Inaltime_Minima() As Double
            Get
                Return int_d.dBtm_MinH
            End Get
            Set(ByVal Value As Double)
                int_d.dBtm_MinH = Value
            End Set
        End Property

        <CategoryAttribute("Borduri (mm)"), _
        DescriptionAttribute("Bordura din dreapta (chenar)"), _
        DefaultValueAttribute(20)> _
        Public Property Margine_Hartie_Dreapta() As Double
            Get
                Return int_d.dB_Right
            End Get
            Set(ByVal Value As Double)
                int_d.dB_Right = Value
            End Set
        End Property
        <CategoryAttribute("Borduri (mm)"), _
        DescriptionAttribute("Bordura din stanga (chenar)"), _
        DefaultValueAttribute(20)> _
        Public Property Margine_Hartie_Stanga() As Double
            Get
                Return int_d.dB_Left
            End Get
            Set(ByVal Value As Double)
                int_d.dB_Left = Value
            End Set
        End Property
        <CategoryAttribute("Borduri (mm)"), _
        DescriptionAttribute("Bordura de sus (chenar)"), _
        DefaultValueAttribute(20)> _
        Public Property Margine_Hartie_Sus() As Double
            Get
                Return int_d.dB_Top
            End Get
            Set(ByVal Value As Double)
                int_d.dB_Top = Value
            End Set
        End Property
        <CategoryAttribute("Borduri (mm)"), _
        DescriptionAttribute("Bordura de jos (chenar)"), _
        DefaultValueAttribute(20)> _
        Public Property Margine_Hartie_Jos() As Double
            Get
                Return int_d.dB_Bottom
            End Get
            Set(ByVal Value As Double)
                int_d.dB_Bottom = Value
            End Set
        End Property

        <CategoryAttribute("Altele"), _
        DescriptionAttribute("Daca e 0 va fi detectata dupa celelalte elemente"), _
        DefaultValueAttribute(20)> _
        Public Property Latime_Tabele() As Double
            Get
                Return int_d.dWidth
            End Get
            Set(ByVal Value As Double)
                int_d.dWidth = Value
            End Set
        End Property


    End Class
    '// ===================================================================== '

End Class
'//  CLASS    =============================================================== '

'//
'//
'//
'//
'//  FUNCTIONS    ----------------------------------------------------------- '

'//  FUNCTIONS    =========================================================== '
'//
'//
'//
'//
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
#End If
